import request from '../utils/request';

const OrdersKey = {
  keys: ['xm_orders', 'gd_orders'],
  begin_time: getDay(7),
  end_time: getDay(1),
};
const MoneyKey = {
  keys: ['xm_money', 'gd_money'],
  begin_time: getDay(7),
  end_time: getDay(1),
};
const headers = { 'Content-Type': 'application/json' };
export function fetch() {
  return request('api/dashboard');
}


export async function linePUS(data) {
  return request('api/chart', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
  });
}

export async function lineOrders(data = OrdersKey) {
  return request('api/chart', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
  });
}
export async function lineMoney(data = MoneyKey) {
  return request('api/chart', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
  });
}
function getDay(x) { // 得到指定的日期
  const myDate = new Date();
  const lw = new Date(myDate - 1000 * 60 * 60 * 24 * x);// 最后一个数字30可改，30天的意思
  const lastY = lw.getFullYear();
  const lastM = lw.getMonth() + 1;
  const lastD = lw.getDate();
  const startdate = `${lastY}-${lastM < 10 ? `0${lastM}` : lastM}-${lastD < 10 ? `0${lastD}` : lastD}`;// 三十天之前日期
  return startdate;
}
